<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <form class="layui-form">
                <div class="layui-form lay-header">
                    <div class="toolbar">
                        <div class="layui-form-item lay-query-content">
                            <div class="lay-query-box">
                                <div class="query-lt">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">所属工序：</label>
                                        <div class="layui-input-inline">
                                            <select name="processId" id="selectProcessId">
                                                <option value="">选择工序</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">质检记录编号：</label>
                                        <div class="layui-input-inline">
                                            <input name="code" class="layui-input" type="text" placeholder="请输入质检任务编号"/>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">工单编号：</label>
                                        <div class="layui-input-inline">
                                            <input name="workOrderCode" class="layui-input" type="text" placeholder="请输入工单编号"/>
                                        </div>
                                    </div>
                                    <!--<div class="layui-inline">
                                        <label class="layui-form-label">送检人：</label>
                                        <div class="layui-input-inline">
                                            <input name="" class="layui-input" type="text" placeholder="请输入送检人"/>
                                        </div>
                                    </div>-->
                                </div>
                                <div class="query-rt">
                                    <div class="layui-inline">
                                        <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog"
                                                lay-submit type="button">查询
                                        </button>
                                        <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit
                                                type="button">重置
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="lay-btn-rows">
                        <div class="lay-btn-box">
                            <div class="lay-btn-lt">
                                <button id="qualityTestingRecordBtnAdd" class="layui-btn icon-btn color-green"
                                        type="button">
                                    添加检测结果
                                </button>
                            </div>
                            <div class="lay-btn-rt">
                            </div>
                        </div>
                    </div>
                </div>
            </form>
            <!-- 表格 -->
            <table class="layui-table" id="qualityTestingRecordTable" lay-filter="qualityTestingRecordTable"></table>
        </div>
    </div>
</div>

<style>

    div[lay-id="addQualityTestingRecordTableList"] .layui-form,
    div[lay-id="addQualityTestingRecordTableList"] .layui-table-box,
    div[lay-id="addQualityTestingRecordTableList"] .layui-table-body,
    div[lay-id="addQualityTestingRecordTableList"] .layui-table-cell {
        overflow: visible;
    }

    div[lay-id="addQualityTestingRecordTableList"] .layui-table-cell {
        padding: 0 10px;
        height: auto;
    }

    div[lay-id="addQualityTestingRecordTableList"] .layui-form-label {
        padding: 10px 2px 0;
        width: auto;
    }

    div[lay-id="addQualityTestingRecordTableList"] .layui-inline {
        margin: 0;
    }

</style>

<!-- 表格操作列 -->
<script type="text/html" id="qualityTestingRecordTableBar">
    <a class="layui-btn layui-btn-xs" lay-event="details">详情</a>
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="print">打印</a>
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="qualityTestingRecordForm">
    <form lay-filter="qualityTestingRecordForm" class="layui-form model-form form-scroll">
        <div class="open-details-box pd-20">
            <input name="id" type="hidden"/>
            <div class="layui-form-item" style="margin: 20px 0;" id="qualityInspectionMOBox">
                <label class="layui-form-label w-auto">质检任务单：</label>
                <div class="layui-input-inline">
                    <input name="qualityInspectionMO" id="qualityInspectionMO" class="layui-input" type="text"
                           placeholder="请选择质检任务单" readonly="readonly" style="cursor: pointer;"/>
                </div>
            </div>
            <div class="layui-form-item" id="addQualityInspectionTaskTableBox" style="display: none">
                <div class="open-details-title">开工单信息</div>
                <!-- 表格 -->
                <table class="layui-table" id="addQualityTestingRecordTable"
                       lay-filter="addQualityTestingRecordTable" style="margin: 1px 0 10px;"></table>
            </div>

            <div class="layui-form-item" id="addQualityInspectionTaskTableListBox" style="display: none">
                <div class="open-details-title">检验结果录入</div>
                <!-- 检验结果录入表格 -->
                <table class="layui-table" id="addQualityTestingRecordTableList"
                       lay-filter="addQualityTestingRecordTableList" style="margin: 1px 0 10px;"></table>
            </div>
            <div class="layui-form-item" id="addQualityInspectionTaskRemarkBox" style="display:none ;">
                <label class="layui-form-label w-auto">备注说明：</label>
                <div class="layui-input-block" style="margin-left: 130px">
                    <textarea placeholder="备注说明" name="remark"
                              style="resize: none; padding: 10px;width: 100%;min-height: 80px;box-sizing: border-box"></textarea>
                </div>
            </div>
        </div>
        <div class="layui-form-item text-right pd-20" style="padding-top: 10px !important;">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="qualityTestingRecordFormSubmit" lay-submit style="display: none">保存
            </button>
        </div>
    </form>
</script>

<!--选择开工单-->
<script type="text/html" id="selectTheWorkProcessTemplate">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 头部操作栏 -->
                <div class="layui-form toolbar">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label w-auto">开工单编号：</label>
                            <div class="layui-input-inline mr0" style="width: 240px;">
                                <input name="code" class="layui-input" type="text" placeholder="开工单编号"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn" lay-filter="selectTheWorkProcessFormSubSearchLog"
                                    lay-submit style="padding: 0 24px;">
                                搜索
                            </button>
                            <button id="selectTheWorkProcessClose" class="layui-btn icon-btn">确认选择</button>
                        </div>
                    </div>
                </div>
                <!-- 表格 -->
                <table class="layui-table" id="selectTheWorkProcessTable"
                       lay-filter="selectTheWorkProcessTable"></table>
            </div>
        </div>
    </div>
</script>

<script type="text/html" id="addQualityTestingRecordTableListBar">
    {{# if(d.isShow == true){  }}
    <a class="layui-btn layui-btn-xs" lay-event="save">保存</a>
    {{# }else{ }}
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    {{# } }}

    <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="print">打印标签</a>
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;

        form.render('select');

        // 渲染表格
        var insTb = table.render({
            elem: '#qualityTestingRecordTable',
            url: config.base + 'production/qualityTesting/admin/qualityTestingRecord/list',
            toolbar: true,
            defaultToolbar: ["filter"],
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers', title: '序号'}
                , {field: 'code', title: '质检记录编码'}
                , {field: 'processName', title: '所属工序'}
                , {field: 'categoryName', title: '质检分类'}
                , {field: 'typeName', title: '质检类型'}
                , {field: 'workOrderCode', title: '所属开工单'}
                , {field: 'deviceCode', title: '送检工站'}
                , {field: 'skuCode', title: '物料编码'}
                , {field: 'submissionQuantity', title: '送检数量'}
                , {field: 'qualifiedQuantity', title: '合格数'}
                , {field: 'passRate', title: '合格率'}
                , {field: 'inspectDeviceCode', title: '检验工站'}
                , {field: 'creatorName', title: '检验员'}
                , {field: 'createTime', title: '检出时间'}
                , {align: 'center', toolbar: '#qualityTestingRecordTableBar', title: '操作', width: 200}
            ]],
            done: function (res, curr, count) {
                //移除按钮
            }
        });

        // 工具条点击事件
        table.on('tool(qualityTestingRecordTable)', function (obj) {
            let data = obj.data;
            if (obj.event === 'details') { //详情
                showDetailsModel(data);
            } else if (obj.event === 'print') { // 打印
                getPrintBarcode(data)
            }
        });

        //监听排序
        table.on('sort(qualityTestingRecordTable)', function (obj) {
            table.reload('qualityTestingRecordTable', {
                initSort: obj
                , where: {
                    sort: obj.field
                    , order: obj.type
                }
            });
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}}, 'data');
        });

        // 重置搜索
        form.on('submit(resets)', function (data) {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            let field = data.field;
            for (let key in field) {
                field[key] = ''
            }
            insTb.reload({where: field, page: {curr: 1}}, 'data');
        });

        // 添加按钮点击事件
        $('#qualityTestingRecordBtnAdd').click(function () {
            showEditModel();
        });

        let addQualityTestingRecordTableData = [], addQualityTestingRecordTableListData = [];

        // 显示编辑弹窗
        function showEditModel(data) {
            addQualityTestingRecordTableData = [];
            addQualityTestingRecordTableListData = [];

            admin.open({
                type: 1,
                area: ['82%', '840px'],
                offset: '65px',
                title: data ? '修改质检记录' : '添加质检记录',
                content: $('#qualityTestingRecordForm').html(),
                success: function () {

                    if (data) {

                        // getWorkOrderDetails(data.workOrderId)
                    } else {
                        $('#qualityInspectionMO').click(function () {
                            showSelectTheWorkProcessTemplateModel()
                        });
                    }


                    let addQualityTestingRecordTb = table.render({
                        elem: '#addQualityTestingRecordTable',
                        data: addQualityTestingRecordTableData,
                        page: false,
                        cellMinWidth: 100,
                        cols: [[
                            {field: 'processName', title: '排产工序'}
                            , {field: 'deviceCode', title: '所属设备'}
                            , {field: 'workOrderCode', title: '所属开工单'}
                            , {field: 'testingCategoryName', title: '质检分类'}
                            , {field: 'testingTypeName', title: '送检类型'}
                            , {field: 'productTypeName', title: '物料类型'}
                            , {field: 'skuCode', title: '物料编号'}
                            , {field: 'skuName', title: '物料名称'}
                            , {field: 'skuSpec', title: '规格码'}
                            , {
                                field: 'accessory', title: '附件', templet: d => {
                                    if (d.accessory) {
                                        return '<a href="' + d.accessory + '" target="_blank" class="layui-btn layui-btn-warm layui-btn-xs">查看附件</a>'
                                    } else {
                                        return ''
                                    }
                                }
                            }
                            , {field: 'submissionQuantity', title: '送检数量'}
                            , {field: 'creatorName', title: '送检人'}
                            , {field: 'createTime', title: '送检时间'}
                        ]],
                        done: function (res, curr, count) {
                            //移除按钮
                            if (!data && addQualityTestingRecordTableData.length > 0) {
                                $('button[lay-filter="qualityTestingRecordFormSubmit"]').show({duration: 300});
                                $('#addQualityInspectionTaskTableBox').show({duration: 300});
                                $('#addQualityInspectionTaskTableListBox').show({duration: 300});
                                $('#addQualityInspectionTaskRemarkBox').show({duration: 300});
                            } else if (data) {
                                $('#addQualityInspectionTaskTableBox').show({duration: 300});
                                $('#addQualityInspectionTaskTableListBox').show({duration: 300});
                                $('#addQualityInspectionTaskRemarkBox').show({duration: 300});
                            }
                        }
                    });

                    let addQualityTestingRecordTbList = table.render({
                        elem: '#addQualityTestingRecordTableList',
                        data: addQualityTestingRecordTableListData,
                        page: false,
                        limit: Number.MAX_VALUE,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'numbers', title: '序号'}
                            , {field: 'code', title: '检验记录编号', width: '170'}
                            , {
                                field: 'sampleCode',
                                title: '样品号',
                                width: '170',
                                templet: d => d.isShow == true ? `<input type="text" class="layui-input" name="sampleCode" value="${d.sampleCode}">` : d.sampleCode
                            }
                            , {
                                field: 'processQualityList', title: '质检参数结果', width: '650',
                                templet: d => {
                                    let selectHTML = '';
                                    d.processQualityList.forEach((item, index) => {
                                        selectHTML += `<div class="layui-inline processQualityValueName">`;
                                        selectHTML += `<label class="layui-form-label" style="max-width: 150px;overflow: hidden" id="${item.processQualityId}">${item.processQualityName}</label><br/>`;
                                        selectHTML += `<div class="layui-input-inline" style="width: 150px;">`;
                                        selectHTML += `<span style="display:${d.isShow == true ? 'none' : ''}">${item.processQualityValueName}</span>`;
                                        selectHTML += `<div style="display:${d.isShow == true ? '' : 'none'}">`;
                                        if (item.type == 2) {
                                            selectHTML += `<input type="text" class="layui-input processQualityValueNameList" value="${item.processQualityValueName}" labelId="${item.processQualityId}">`
                                        } else if (item.type == 1) {
                                            selectHTML += `<select name="processQualityValueNameList" labelId="${item.processQualityId}" class="processQualityValueNameList">`;
                                            selectHTML += '<option value="">请选择' + item.processQualityName + '</option>';
                                            item.processQualityListData.forEach((item1, index1) => {
                                                if (item1.id == item.processQualityValueId) {
                                                    selectHTML += '<option value="' + item1.id + '" selected="">' + item1.processQualityValue + '</option>';
                                                } else {
                                                    selectHTML += '<option value="' + item1.id + '">' + item1.processQualityValue + '</option>';
                                                }
                                            });
                                            selectHTML += `</select>`;
                                        }
                                        selectHTML += `</div>`;
                                        selectHTML += `</div></div>`;
                                        if (index > 0 && (index + 1) % 4 == 0) {
                                            selectHTML += '<br />'
                                        }
                                    });
                                    return selectHTML;
                                }
                            }
                            , {
                                field: 'qualityTestingResult', title: '质检评定结果', width: '140',
                                templet: d => {
                                    let selectHTML = `<span style="display:${d.isShow == true ? 'none' : ''}">${d.qualityTestingResultValue.name}</span>`;
                                    selectHTML += `<div style="display:${d.isShow == true ? '' : 'none'}"><select name="qualityTestingResult">`;
                                    selectHTML += '<option value="">质检评定结果</option>';
                                    d.qualityTestingResultData.forEach(item => {
                                        if (item.value == d.qualityTestingResultValue.value) {
                                            selectHTML += '<option value="' + item.value + '" selected="">' + item.name + '</option>';
                                        } else {
                                            selectHTML += '<option value="' + item.value + '">' + item.name + '</option>';
                                        }
                                    });
                                    selectHTML += '</select></div>';
                                    return selectHTML;
                                }
                            }
                            , {
                                field: 'remark',
                                title: '备注',
                                width: '140',
                                templet: d => d.isShow == true ? `<input type="text" class="layui-input" name="addQualityTestingRecordRemark" value="${d.remark}">` : d.remark

                            }
                            , {
                                align: 'left',
                                title: '操作',
                                toolbar: '#addQualityTestingRecordTableListBar',
                                width: '150'
                            }
                        ]],
                        done: function (res, curr, count) {
                            //移除按钮
                        }

                    });

                    form.on("select", function (data) {
                        if ($(data.elem).attr('name') == 'qualityTestingResult') {
                            addQualityTestingRecordTableListData[$(data.elem).parents('tr').index()].qualityTestingResult = data.value;
                            addQualityTestingRecordTableListData[$(data.elem).parents('tr').index()].qualityTestingResultValue = {
                                name: data.elem[data.elem.selectedIndex].text,
                                value: data.value
                            };
                        } else if ($(data.elem).attr('class') == 'processQualityValueNameList') {
                            addQualityTestingRecordTableListData[$(data.elem).parents('tr').index()].processQualityList[$(data.elem).parents('.processQualityValueName').index() - 1].processQualityValueId = data.value;
                            addQualityTestingRecordTableListData[$(data.elem).parents('tr').index()].processQualityList[$(data.elem).parents('.processQualityValueName').index() - 1].processQualityValueName = data.elem[data.elem.selectedIndex].text;
                        }

                    });

                    $("body").delegate("[lay-id='addQualityTestingRecordTableList'] .processQualityValueNameList", "change", function () {
                        if (addQualityTestingRecordTableListData[$(this).parents('tr').index()]) {
                            addQualityTestingRecordTableListData[$(this).parents('tr').index()].processQualityList[$(this).parents('.processQualityValueName').index()].processQualityValueName = $(this).val().trim();
                        }
                    });

                    $("body").delegate("[lay-id='addQualityTestingRecordTableList'] input[name='addQualityTestingRecordRemark']", "change", function () {
                        if (addQualityTestingRecordTableListData[$(this).parents('tr').index()]) {
                            addQualityTestingRecordTableListData[$(this).parents('tr').index()].remark = $(this).val().trim();
                        }
                    });

                    $("body").delegate("[lay-id='addQualityTestingRecordTableList'] input[name='sampleCode']", "change", function () {
                        if (addQualityTestingRecordTableListData[$(this).parents('tr').index()]) {
                            addQualityTestingRecordTableListData[$(this).parents('tr').index()].sampleCode = $(this).val().trim();
                        }
                    });

                    // 工具条点击事件
                    table.on('tool(addQualityTestingRecordTableList)', function (obj) {
                        let data = obj.data;
                        if (obj.event === 'edit') { //修改
                            addQualityTestingRecordTableListData[$(obj.tr).index()].isShow = true;
                            addQualityTestingRecordTbList.reload({data: addQualityTestingRecordTableListData});
                        } else if (obj.event === 'save') { // 保存
                            if (addQualityTestingRecordTableListData[$(obj.tr).index()].sampleCode == '') {
                                layer.msg('请输入样品号', {icon: 2});
                                return false;
                            } else if (addQualityTestingRecordTableListData[$(obj.tr).index()].qualityTestingResult == '') {
                                layer.msg('请选择质检评定结果', {icon: 2});
                                return false;
                            }
                            for (let i = 0; i < addQualityTestingRecordTableListData[$(obj.tr).index()].processQualityList.length; i++) {
                                if (addQualityTestingRecordTableListData[$(obj.tr).index()].processQualityList[i].processQualityValueName == '') {

                                    layer.msg('请输入' + addQualityTestingRecordTableListData[$(obj.tr).index()].processQualityList[i].processQualityName, {icon: 2});
                                    return false
                                }
                            }

                            addQualityTestingRecordTableListData[$(obj.tr).index()].isShow = false;
                            addQualityTestingRecordTbList.reload({data: addQualityTestingRecordTableListData});
                        }
                    });

                    // 表单提交事件
                    form.on('submit(qualityTestingRecordFormSubmit)', function (d) {
                        let dataObj = [];
                        addQualityTestingRecordTableListData.forEach((item, index) => {
                            if (!item.isShow) {
                                dataObj[index] = {};
                                dataObj[index].remark = item.remark;
                                dataObj[index].code = item.code;
                                dataObj[index].sampleCode = item.sampleCode;
                                dataObj[index].qualityTestingResult = item.qualityTestingResult;
                                dataObj[index].qualityValueList = [];
                                item.processQualityList.forEach((item1, index1) => {
                                    let qualityValueListObj = {};
                                    qualityValueListObj.processQualityId = item1.processQualityId;
                                    qualityValueListObj.processQualityName = item1.processQualityName;
                                    qualityValueListObj.processQualityValueId = item1.processQualityValueId;
                                    qualityValueListObj.processQualityValueName = item1.processQualityValueName;
                                    dataObj[index].qualityValueList.push(qualityValueListObj)
                                })
                            }
                        });
                        if (dataObj.length == 0) {
                            layer.msg('请保存或添加检验结果', {icon: 5});
                            return false
                        }

                        d.field.testingRecordDetail = dataObj;
                        d.field.qualityTestingTaskId = addQualityTestingRecordTableData[0].qualityTestingTaskId;
                        layer.load(2);
                        admin.req(data ? 'production/qualityTesting/admin/qualityTestingRecord/update' : 'production/qualityTesting/admin/qualityTestingRecord/submitTestingRecord', JSON.stringify(d.field), function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('qualityTestingRecordTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, data ? 'PUT' : 'POST', true, 'application/json; charset=utf-8');
                        return false;
                    });
                }
            });
        }

        function showSelectTheWorkProcessTemplateModel() {
            let selectTheWorkProcessTemplate = admin.open({
                type: 1,
                title: '选择开工单',
                area: '75%',
                offset: '120px',
                content: $('#selectTheWorkProcessTemplate').html(),
                success: function () {
                    form.render("select");
                    // 渲染表格
                    let selectTheWorkProcessTable = table.render({
                        elem: '#selectTheWorkProcessTable',
                        url: config.base + 'production/qualityTesting/admin/workOrderQualityTestingTask/list',
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'radio'}
                            , {field: 'code', title: '质检任务单编码'}
                            , {field: 'processName', title: '所属工序'}
                            , {field: 'testingCategoryName', title: '质检分类'}
                            , {field: 'testingTypeName', title: '质检类型'}
                            , {field: 'workOrderCode', title: '所属开工单'}
                            , {field: 'deviceCode', title: '送检工站'}
                            , {field: 'skuCode', title: '物料编码'}
                            , {field: 'creatorName', title: '送检人'}
                            , {field: 'submissionQuantity', title: '送检数量'}
                            , {field: 'statusDesc', title: '状态'}
                            , {field: 'inspectDeviceCode', title: '检验工站'}
                            , {field: 'inspector', title: '检验员'}
                        ]],
                    });

                    // 搜索
                    form.on('submit(selectTheWorkProcessFormSubSearchLog)', function (data) {
                        selectTheWorkProcessTable.reload({
                            where: data.field,
                            page: {curr: 1}
                        }, 'data');
                    });

                    // 确认选择
                    $('#selectTheWorkProcessClose').click(function () {
                        let checkStatus = table.checkStatus('selectTheWorkProcessTable'); //test即为基础参数id对应的值
                        let dataS = checkStatus.data[0];
                        if (checkStatus.data.length == 0) {
                            layer.msg("请选择开工单", {icon: 2, time: 1000});
                        } else {
                            getWorkOrderDetails(dataS.id);
                            $("#qualityInspectionMO").val(dataS.code);
                            layer.close(selectTheWorkProcessTemplate);
                        }
                    });
                }
            })
        }

        // 获取开工单信息和工序信息
        function getWorkOrderDetails(id, _type) {
            // addQualityInspectionTaskTableData
            let dataList = [], dataS = '';
            // 查询开工单信息
            admin.reqSync('production/qualityTesting/admin/qualityTestingRecord/getTestingTaskByTaskId', {taskId: id},
                res => {
                    if (res.code == 200) {
                        res.data.qualityTestingTaskId = id;
                        addQualityTestingRecordTableData[0] = res.data;
                        dataS = res.data;
                        table.reload('addQualityTestingRecordTable', {data: addQualityTestingRecordTableData});
                    }
                }, 'GET');
            // 查询所有质量参数分类（检验工单分类）
            admin.reqSync('production/qualityTesting/admin/qualityTestingRecord/getInspectionResultsData', {taskId: 1},
                res => {
                    if (res.code == 200) {
                        if (res.data.length == 0) {
                            layer.msg('请先设置质检参数', {icon: 5})
                        } else {
                            dataList = res.data;
                        }
                    }
                }, 'GET');


            if (dataS && dataS.submissionQuantity > 0) {
                addQualityTestingRecordTableListData = [];
                for (let i = 0; i < dataS.submissionQuantity; i++) {
                    addQualityTestingRecordTableListData[i] = {};
                    addQualityTestingRecordTableListData[i].remark = ''; // 备注
                    addQualityTestingRecordTableListData[i].isShow = true;
                    addQualityTestingRecordTableListData[i].code = dataS.workOrderCode + '-' + (i + 1); //	检验记录编号
                    addQualityTestingRecordTableListData[i].sampleCode = ''; //	样品号
                    addQualityTestingRecordTableListData[i].qualityTestingResult = '';
                    addQualityTestingRecordTableListData[i].qualityTestingResultValue = {
                        name: '', value: ''
                    }; //质检评定结果
                    addQualityTestingRecordTableListData[i].qualityTestingResultData = [
                        {name: '合格', value: 'qualified'},
                        {name: '不合格', value: 'unqualified'},
                        {name: '其他', value: 'other'}
                    ];//质检评定结果下拉数据


                    addQualityTestingRecordTableListData[i].processQualityList = []; // 质检参数结果
                    dataList.forEach((item, index) => {
                        let processQualityObj = {};
                        processQualityObj.processQualityId = item.id;  // 质检参数结果 label的id
                        processQualityObj.type = item.type;  // 质检参数结果 label的类型
                        processQualityObj.processQualityName = item.name; // 质检参数结果 label的name
                        processQualityObj.processQualityValueId = ''; // 质检参数结果 下拉选项选择值的id
                        processQualityObj.processQualityValueName = ''; // 质检参数结果 下拉选项选择值的name
                        processQualityObj.processQualityListData = item.qualityValueVOList;// 质检参数结果 所以下拉选项
                        addQualityTestingRecordTableListData[i].processQualityList.push(processQualityObj)
                    })
                }
                table.reload('addQualityTestingRecordTableList', {data: addQualityTestingRecordTableListData});
            }

        }

        function showDetailsModel(data) {
            admin.open({
                type: 1,
                area: ['82%', '840px'],
                offset: '65px',
                title: '质检记录表详情',
                content: $('#qualityTestingRecordForm').html(),
                success: function () {
                    let qualityTestingRecordTableData = [];
                    $('textarea[name="remark"]').attr('disabled', 'disabled');
                    $('textarea[name="remark"]').val(data.remark);
                    $('#qualityInspectionMOBox').hide();
                    $('.open-details-title').css('margin', '10px 0');
                    admin.reqSync('production/qualityTesting/admin/qualityTestingRecord/getTestingTaskRecordDetail',
                        {qualityTestingRecordId: data.id},
                        res => {
                            if (res.code === 200) {
                                res.data.forEach((item, index) => {
                                    qualityTestingRecordTableData.push(item)
                                });
                            }
                        }, 'get');

                    let addQualityTestingRecordTb = table.render({
                        elem: '#addQualityTestingRecordTable',
                        data: [data],
                        page: false,
                        cellMinWidth: 100,
                        cols: [[
                            {field: 'taskCode', title: '质检任务单编号'}
                            , {field: 'processName', title: '排产工序'}
                            , {field: 'deviceCode', title: '所属设备'}
                            , {field: 'workOrderCode', title: '所属开工单'}
                            , {field: 'testingCategoryName', title: '质检分类'}
                            , {field: 'testingTypeName', title: '质检类型'}
                            , {field: 'skuCode', title: '物料编号'}
                            , {field: 'skuSpec', title: '规格码'}
                            , {
                                field: 'accessory', title: '附件', templet: d => {
                                    if (d.accessory) {
                                        return '<a href="' + d.accessory + '" target="_blank" class="layui-btn layui-btn-warm layui-btn-xs">查看附件</a>'
                                    } else {
                                        return ''
                                    }
                                }
                            }
                            , {field: 'submissionQuantity', title: '送检数量'}
                            , {field: 'creatorName', title: '送检人'}
                            , {field: 'createTime', title: '送检时间'}
                            , {field: 'passRate', title: '合格率'}
                        ]],
                        done: function (res, curr, count) {
                            //移除按钮
                            $('#addQualityInspectionTaskTableBox').show({duration: 300});
                            $('#addQualityInspectionTaskTableListBox').show({duration: 300});
                            $('#addQualityInspectionTaskRemarkBox').show({duration: 300});
                        }
                    });

                    let addQualityTestingRecordTbList = table.render({
                        elem: '#addQualityTestingRecordTableList',
                        data: qualityTestingRecordTableData,
                        page: false,
                        limit: Number.MAX_VALUE,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'numbers', title: '序号'}
                            , {field: 'code', title: '检验记录编号', width: '150'}
                            , {field: 'sampleCode', title: '样品号'}
                            , {
                                field: 'processQualityList', title: '质检参数结果', width: '650', templet: d => {
                                    let selectHTML = '';
                                    d.qualityValueList.forEach((item, index) => {
                                        selectHTML += `<div class="layui-inline">`;
                                        selectHTML += `<label class="layui-form-label" style="max-width: 150px;overflow: hidden">${item.processQualityName}</label><br/>`;
                                        selectHTML += `<div class="layui-input-inline" style="width: 150px;">`;
                                        selectHTML += `<span style="color: red;">${item.processQualityValueName}</span>`;
                                        selectHTML += `</div></div>`;
                                        if (index > 0 && (index + 1) % 4 == 0) {
                                            selectHTML += '<br />'
                                        }
                                    });
                                    return selectHTML
                                }
                            }
                            , {field: 'qualityTestingResultDesc', title: '质检评定结果'}
                            , {field: 'remark', title: '备注', width: '150'}
                            , {field: 'createTime', title: '检出时间', width: '150'}
                            , {field: 'creatorName', title: '检验员', width: '150'}

                        ]],
                        done: function (res, curr, count) {
                            //移除按钮
                        }

                    });
                }
            });
        }


        // 请求条码接口
        function getPrintBarcode(data) {
            layer.load(2);
            admin.req('enterprise/product/admin/productPackLabel/getBarCode', {code: data.code}, function (res) {
                layer.closeAll('loading');
                if (res.code == 200) {
                    var newstr = `
                        <div style="padding: 20px;width: 100%;box-sizing: border-box;">
                            <div style="height: 150px;width: 100%">
                                <div style="width: 150px;float: left;height: 100%;">
                                    <img src="${res.data}" style="max-width: 100%; width: 100%;height: 100%;"/>
                                </div>
                                <div style="width: calc(100% - 150px); float: left;height: 100%; box-sizing: border-box; padding: 15px; font-size: 16px">
                                    ${data.skuCode}
                                </div>
                            </div>
                            <p style="margin-top: 5px;font-size: 16px;width: 100%;box-sizing: border-box;height: 20px; overflow: hidden"> ${data.code}</p>
                        </div>
                    `;
                    printBarcode(newstr)
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'GET');
        }

        // 打印条码
        function printBarcode(data) {
            admin.open({
                type: 1,
                area: ['330px', '350px'],
                offset: '65px',
                title: "打印预览",
                content: data,
                btn: ['打印', '取消'],
                yes: function () {
                    let newWin = window.open("Print_window", "_blank");//新打开一个空窗口
                    newWin.document.write(data);//将表格添加进新的窗口
                    newWin.document.close();//在IE浏览器中使用必须添加这一句
                    newWin.focus();//在IE浏览器中使用必须添加这一句
                    newWin.print();//打印
                    newWin.close();//关闭窗口
                },
                btn2: function () {
                    layer.closeAll();
                }

            })

        }

        // 导出excel
        $('#qualityTestingRecordBtnExport').click(function () {
            var checkRows = table.checkStatus('qualityTestingRecordTable');
            if (checkRows.data.length == 0) {
                layer.msg('请选择要导出的数据', {icon: 2});
            } else {
                table.exportFile(insTb.config.id, checkRows.data, 'xls');
            }
        });

    });
</script>